package cn.tedu.spring.example;

import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

public class TestUser {
    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
        /*
            1.通过注解方式: 创建Spring Bean对象,并放到IoC容器中;
            2.通过getBean方法: 从 IoC容器 中,获取 Spring Bean 对象
         */
        ApplicationContext context = new AnnotationConfigApplicationContext("cn.tedu.spring.example");
        User user1 = context.getBean(User.class);
        user1.userRun();

        /*
            创建对象方式2: 通过new关键字
         */
        User user2 = new User();
        user2.userRun();

        /*
            创建对象方式3: 通过反射方式
         */
        Class zz = Class.forName("cn.tedu.spring.example.User");
        User user3 = (User) zz.newInstance();
        user3.userRun();
    }
}







